import Vue from 'vue'
import { BaseUrl } from './Baseurl/common.js';
import { Toast } from 'mint-ui';
//京东跳转页面
Vue.prototype.commodity = function(id, couponMoney) {
	var jdurl;
//	this.token = localStorage.setItem('yunId', this.token);
    var token = localStorage.getItem('token')
	if(couponMoney == 0) {
		jdurl = BaseUrl + "jd/getUrl?appId=wap" + "&spuId=" + id + "&token=" + token
	} else {
		jdurl = BaseUrl + "jd/getConUrl/?appId=wap" + "&spuId=" + id + "&token=" + token
	}
	this.$http.get(jdurl).then(res => {

		if(res.data.code == "10000") {
			if(res.data.data != '') {
				window.location.href = res.data.data
			} else{
				this.$router.push({
					path: '/couponEmpty?id='+ id
				})
				location.reload();
			}
		}
	}).catch(error=>{
		Toast({
			message: "网络异常",
			position: 'middle',
			duration: 3000
		})
	})
}
//yh跳转页面
Vue.prototype.yhcommodity=function(id) {
	this.$router.push({
		path: '/redpackage?type=1' + "&goodsId=" + id
	})
}

//pdd 跳转页面
Vue.prototype.pddcommodity=function(id) {
	var token = localStorage.getItem('token');
	var url = BaseUrl + 'yhlm/getConUrl?appId=wap' + '&spuId=' + id + '&token=' + token;
	this.$http.get(url).then(res=>{
		if(res.data.code == '10000'){
			window.location.href = res.data.data
		}else{
			Toast({
				message: res.data.msg,
				position: 'middle',
				duration: 3000
			})
		}
	}).catch(error=>{
		Toast({
			message: "网络异常",
			position: 'middle',
			duration: 3000
		})
	})
}